import _imports  # 只在此项目有效，其他项目，请去掉此 import
import pybi as pbi
import pandas as pd
from src.data.dataset import load_df

easy_charts = pbi.easy_echarts


# pandas 加载数据
df = load_df("某咖啡公司销售数据.xlsx")

# 设置数据源
data = pbi.set_source(df)


with pbi.flowBox():
    # 切片器
    for col in ["市场类别", "区域", "产品类别", "产品名称"]:
        pbi.add_slicer(data[col])


with pbi.flowBox():
    # bar
    opts = easy_charts.make_bar(data, x="产品类别", y="利润额", color="区域")
    pbi.add_echart(opts)

    # 条形图
    pbi.add_echart(opts.reverse_axis())

    # 线图
    opts = easy_charts.make_line(data, x="产品类别", y="利润额", color="区域")
    pbi.add_echart(opts)

    # pie
    opts = easy_charts.make_pie(data, name="产品类别", value="利润额")
    pbi.add_echart(opts)

    # 散点
    opts = easy_charts.make_scatter(data, x="销售额", y="利润额", color="产品类别")
    pbi.add_echart(opts)

pbi.to_html("test.html")
